package com.rm.zeyou.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.rm.zeyou.entity.User;
import com.rm.zeyou.response.ApiRestResponse;
import com.rm.zeyou.service.RefundOrderService;
import com.rm.zeyou.util.login.LoginUtil;
import com.rm.zeyou.vo.request.ApplyRefundVo;
import com.rm.zeyou.vo.response.ApplyRefundIndexResponseVo;
import com.rm.zeyou.vo.response.RefundOrderDetailResponseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 售后订单表 前端控制器
 * </p>
 *
 * @author YanYang
 * @since 2025-04-01 10:26:48
 */
@Api(tags = "售后退款相关")
@RestController
@RequestMapping("/api/refundOrder")
public class RefundOrderController {
    @Resource
    private RefundOrderService refundOrderService;
    @Resource
    private LoginUtil loginUtil;

    @ApiOperation(value = "申请退款页面")
    @GetMapping("applyRefundIndex")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<ApplyRefundIndexResponseVo> applyRefundIndex(@RequestParam String orderNo) {
        User user = loginUtil.getUser();
        return refundOrderService.applyRefundIndex(user,orderNo);
    }

    @ApiOperation(value = "申请退款")
    @PostMapping("applyRefund")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<Integer> applyRefund(@RequestBody ApplyRefundVo refundVo) throws Exception {
        User user = loginUtil.getUser();
        return refundOrderService.applyRefund(user,refundVo);
    }

    @ApiOperation(value = "退款订单详情")
    @GetMapping("refundOrderDetail")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<RefundOrderDetailResponseVo> refundOrderDetail(@RequestParam String orderNo) {
        User user = loginUtil.getUser();
        return refundOrderService.refundOrderDetail(user,orderNo);
    }

}
